package com.yykj.hospital.server.controller;

import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.client.dto.DepartmentListDTO;
import com.yykj.hospital.client.dto.HospitalDepartmentDTO;
import com.yykj.hospital.client.dto.HotDoctorDTO;
import com.yykj.hospital.client.form.HotDepartmentEditForm;
import com.yykj.hospital.server.form.HospitalBannerForm;
import com.yykj.hospital.server.form.HospitalHotDoctorEditForm;
import com.yykj.hospital.server.model.entity.HospitalBanner;
import com.yykj.hospital.server.service.DepartmentService;
import com.yykj.hospital.server.service.HospitalDoctorService;
import com.yykj.hospital.server.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/backstage/hospital")
@Api(tags = {"医院首页配置"})
@SuppressWarnings("unchecked")
public class HospitalHomeController {
    //===============================================================================================================
    @PostMapping("/hot/department/add")
    @ApiOperation("热门科室--创建科室")
    public ResultVO<HospitalDepartmentDTO> addHot(
            @RequestBody HotDepartmentEditForm hotDepartmentEditForm) {
        return ResultVO.success(departmentService.editHotDepartment(hotDepartmentEditForm));
    }

    @PutMapping("/hot/department/edit")
    @ApiOperation("热门科室--修改科室")
    public ResultVO<HospitalDepartmentDTO> editHot(
            @RequestBody HotDepartmentEditForm hotDepartmentEditForm) {
        return ResultVO.success(departmentService.editHotDepartment(hotDepartmentEditForm));
    }

    @GetMapping("/hot/department/list")
    @ApiOperation("热门科室--科室列表")
    public ResultVO<List<HospitalDepartmentDTO>> listHot(@RequestParam(name = "hospitalId") Integer hospitalId) {
        return ResultVO.success(departmentService.listBackstageHotDepartment(hospitalId));
    }

    @DeleteMapping("/hot/department/delete/{id}")
    @ApiOperation("热门科室--删除科室")
    public ResultVO  deleteHot(@PathVariable Integer id) {
        departmentService.deleteHotDepartment(id);
        return ResultVO.success();
    }

    //===============================================================================================================
    @PostMapping("/hot/doctor/add")
    @ApiOperation("推荐医生--添加")
    public ResultVO<HotDoctorDTO> addHotDoctor(@RequestBody HospitalHotDoctorEditForm form) {
        return ResultVO.success(doctorService.editHotDoctor(form));
    }


    @PutMapping("/hot/doctor/edit")
    @ApiOperation("推荐医生--修改")
    public ResultVO<HotDoctorDTO> editHotDoctor(@RequestBody HospitalHotDoctorEditForm form) {
        return ResultVO.success(doctorService.editHotDoctor(form));
    }

    @DeleteMapping("/hot/doctor/delete/{doctorId}")
    @ApiOperation("推荐医生--删除")
    public ResultVO deleteHotDoctor(@PathVariable String doctorId) {
        doctorService.deleteHotDoctor(doctorId);
        return ResultVO.success();
    }


    @GetMapping("/hot/doctor/list")
    @ApiOperation("推荐医生--列表")
    public ResultVO<List<HotDoctorDTO>> listHotDoctor(@RequestParam(name = "hospitalId") Integer hospitalId) {
        return ResultVO.success(doctorService.listHotDoctor(hospitalId));
    }

    //===============================================================================================================
    @PostMapping("/banner/add")
    @ApiOperation("banner配置--添加")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalBanner> addBanner(@RequestBody HospitalBannerForm form) {
        return ResultVO.success(hospitalService.editBanner(form));
    }

    @PutMapping("/banner/edit")
    @ApiOperation("banner配置--修改")
    public ResultVO<HospitalBanner> editBanner(@RequestBody HospitalBannerForm form) {
        return ResultVO.success(hospitalService.editBanner(form));
    }

    @DeleteMapping("/banner/delete/{id}")
    @ApiOperation("banner配置--删除")
    public ResultVO deleteBanner(@PathVariable Integer id) {
        hospitalService.deleteBanner(id);
        return ResultVO.success();
    }


    @GetMapping("/banner/list")
    @ApiOperation("banner配置--列表")
    public ResultVO<List<HospitalBanner>> listBanner(@RequestParam(name = "hospitalId") Integer hospitalId) {
        return ResultVO.success(hospitalService.listBanner(hospitalId));
    }
    //===============================================================================================================
    private DepartmentService departmentService;

    private HospitalDoctorService doctorService;

    private HospitalService hospitalService;

    @Autowired
    public void setDepartmentService(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @Autowired
    public void setDoctorService(HospitalDoctorService doctorService) {
        this.doctorService = doctorService;
    }
    @Autowired
    public void setHospitalService(HospitalService hospitalService) {
        this.hospitalService = hospitalService;
    }
}
